<template>
  <div class="user-login">
    <div class="user-login-bg" :style="{'background-image':`url(${backgroundImage})`}"></div>
    <div class="content-wrapper">
      <h2 class="slogan">
        欢迎使用 <br /> 自动化电工学在线考试系统
      </h2>
      <div class="form-container">
        <h4 class="form-title">登录</h4>
        <el-form ref="form" :model="user" label-width="0">
          <div class="form-items">
            <el-row class="form-item">
              <el-col>
                <el-form-item prop="username" :rules="[ { required: true, message: '用户名不能为空'}]">
                  <div class="form-line">
                    <i class="fa fa-user-o fa-fw"></i>

                    <el-input placeholder="用户名" v-model="user.username"></el-input>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="form-item">
              <el-col>
                <el-form-item prop="password" :rules="[ { required: true, message: '密码不能为空'}]">
                  <div class="form-line">
                    <i class="fa fa-key fa-fw"></i>
                    <el-input type="password" placeholder="密码" v-model="user.password"></el-input>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class=form-item>
              <el-col>
                <el-form-item>
                  <el-checkbox class="checkbox">记住账号</el-checkbox>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="form-item">
              <el-button type="primary" class="submit-btn" size="small" @click="submitBtn" :loading="loading">
                登 录
              </el-button>
            </el-row>
          </div>
          <el-row class="tips">
            <span class="line">|</span>
            <a href="/" class="link">
              忘记密码
            </a>
          </el-row>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import BasicContainer from "@vue-materials/basic-container";
import backgroundImage from "@/assets/bg.png";
export default {
  components: { BasicContainer },
  name: "UserLogin",

  data() {
    return {
      loading: false,
      backgroundImage: backgroundImage,
      user: {
        username: "test",
        password: "123"
      }
    };
  },

  created() {},

  methods: {
    submitBtn(ev) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.logining = true;
          this.$api.login(this.user).then(res => {
            this.logining = false;
            sessionStorage.setItem("user", JSON.stringify(res));
            this.$router.push({ path: "/main" });
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.user-login {
  .user-login-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: cover;
  }
  .el-checkbox__label {
    color: #999;
    font-size: 13px;
  }
  .content-wrapper {
    position: absolute;
    top: -100px;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 1080px;
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .slogan {
      text-align: center;
      color: rgb(10, 2, 2);
      font-size: 36px;
      letter-spacing: 2px;
      line-height: 48px;
    }
  }
  .form-container {
    display: flex;
    justify-content: center;
    flex-direction: column;
    padding: 30px 40px;
    background-color: #fff;
    border-radius: 6px;
    box-shadow: 1px 1px 2px #eee;
  }
  .el-form-item {
    margin-bottom: 15px;
  }
  .form-Item {
    position: relative;
    flex-direction: column;
  }
  .form-line {
    position: relative;
    display: flex;
    align-items: center;
    &:after {
      content: "";
      position: absolute;
      bottom: 3px;
      left: 0;
      width: 100%;
      box-sizing: border-box;
      border-width: 1px;
      border-style: solid;
      border-top: 0;
      border-left: 0;
      border-right: 0;
      border-color: #dcdcdc;
      border-radius: 0;
    }
  }
  .el-input {
    width: 240px;
    input {
      border: none;
      margin: 0;
      padding-left: 10px;
      font-size: 13px;
    }
  }
  .form-title {
    margin: 0 0 20px;
    text-align: center;
    color: #3080fe;
    letter-spacing: 12px;
  }
  .input-icon {
    color: #999;
  }
  .checkbox {
    margin-left: 5px;
  }
  .submit-btn {
    margin-bottom: 25px;
    width: 100%;
    background: #3080fe;
    border-radius: 28px;
  }
  .tips {
  }
  .link {
    color: #999;
    text-decoration: none;
    font-size: 13px;
  }
  .line {
    color: #dcd6d6;
    margin: 0 8px;
  }
}

@media screen and (max-width: 720px) {
  .user-login {
    .content-wrapper {
      margin: 20px auto;
      top: 40px;
      max-width: 300px;
      display: block;
      .slogan {
        color: #666;
        font-size: 22px;
        line-height: 30px;
      }
    }
  }
}
</style>

<style lang="scss">
.user-login {
  .el-input__inner {
    border: 0px !important;
  }
}
</style>
